package com.centaur0.io;

import java.io.PrintWriter;
import java.util.Locale;

import javax.servlet.ServletOutputStream;

public class PrintWriterWrapper extends PrintWriter {
	ServletOutputStream out;
	
	@Override
	public void flush() {
		try{
			out.flush();
		} catch(Exception e){}
	}
	
	public PrintWriterWrapper(ServletOutputStream out) {
		super(new WriterImpl(out));
		this.out = out;
	}
	
	@Override
	public PrintWriter printf(Locale l, String format, Object... args) {
		String.format(l, format, args);
		return this;
	}
	
	@Override
	public PrintWriter append(char c) {
		try{
			this.out.print(Character.toString(c));
			return this;
		} catch(Exception e){
			return null;
		}
	}
	
	@Override
	public PrintWriter append(CharSequence csq) {
		try{
			out.print(csq.toString());
			return this;
		} catch(Exception e){
			return null;
		}
	}
	
	@Override
	public PrintWriter append(CharSequence csq, int start, int end) {
		try{
			out.print(csq.subSequence(start, end).toString());
			return this;
		} catch(Exception e){
			return null;
		}
	}
	
	@Override
	public void print(char c) {
		try{
			out.print(c);
		} catch(Exception e){}
	}
	
	@Override
	public void print(char[] s) {
		try{
			out.print(new String(s));
		} catch(Exception e){}
	}
	
	@Override
	public void print(int i) {
		try{
			out.write(i);
		} catch(Exception e){}
	}
	
	@Override
	public void print(String s) {
		try{
			out.print(s);
		} catch(Exception e){}
	}
	
	@Override
	public void print(Object obj) {
		print(obj.toString());
	}
	
	@Override
	public PrintWriter printf(String format, Object... args) {
		write(String.format(format, args));
		return this;
	}
	
	@Override
	public void write(int c) {
		try{
			out.write(c);
		} catch(Exception e){}
	}
	
	@Override
	public void write(String s) {
		try{
			out.print(s);
		} catch(Exception e){}
	}
}